﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LEET.StaticAnalisys;
using LEET.LEETCommon;

namespace LEET.StaticAnalisys.Visitors
{
    public class InfiniteRecursionDetection : IVisitor
    {
        public void Visit(INode node)
        {
            ISet<String> set = new SortedSet<String>();
            INode current = node;
            while (current != null)
            {
                if (NodeTypes.EMBED_TYPE.Equals(node.InstructionType))
                    if (set.Contains(current.Name))
                    {
                        throw new CycleDetectedException();
                    }
                    else
                    {
                        set.Add(current.Name);
                    }
                current = current.Parent;
            }

        }
    }
}
